<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
use Common\Model\CategoryModel;

class CategoryController extends  CommonController{


	public function index(){
		$model = new CategoryModel();
		$cateList = $model->getCategoryList();

		$this->assign('cateList',$cateList);
		$this->display();
	}

	public function add(){
		$model = new CategoryModel();
		if(IS_POST){
			$model = new CategoryModel();
			if(!$model->addCategory()){
				$this->error($model->getError());
			}
			$this->success('栏目添加成功',U('admin/category/index'));
		}
		$cateList = $model->getCategoryList();
		$this->assign('cateList',$cateList);
		$this->display();
	}


	public function edit(){
		$model = new CategoryModel();
		$id = I('get.id');
		if(IS_POST){
			if(!$model->editCategory()){
				$this->error($model->getError());
			}
			$this->success('栏目修改成功',U('admin/category/index'));
		}

		$cateList = $model->getCategoryList();
		$data = $model->findById($id);
		$this->assign('cateList',$cateList)->assign('data',$data);

		$this->display();
	}

	public function del(){
		$id = I('get.id');
		$model = new CategoryModel();
		$model->delete($id);
		$this->success('删除完成');
	}

}
